const Mock = require("mockjs");
const getQuestionList = require("../data/getQuestionData.js");

const Random = Mock.Random;

module.exports = [
  // 获取单个试卷内容
  {
    url: "/api/question/:id",
    method: "get",
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
          title: Random.ctitle(),
          desc: "问卷描述",
          css: "",
          js: "",
          isPublished: true,
          componentList: [
            {
              fe_id: Random.id(),
              type: "questionTitle",
              title: "标题", // 图层中需要显示
              isHidden: false,
              isLocked: false,
              props: {
                text: "个人信息调研",
                level: 1,
                isCenter: false,
              },
            },
            {
              fe_id: Random.id(),
              type: "questionInput",
              title: "输入框",
              isHidden: false,
              isLocked: false,
              props: {
                title: "你的姓名",
                placeholder: "请输入",
              },
            },
            {
              fe_id: Random.id(),
              type: "questionTextarea",
              title: "多行输入框",
              isHidden: false,
              isLocked: false,
              props: {
                title: "你的经历",
                placeholder: "请输入",
              },
            },
            {
              fe_id: Random.id(),
              type: "questionInput",
              title: "输入框",
              isHidden: false,
              isLocked: false,
              props: {
                title: "你的电话",
                placeholder: "请输入",
              },
            },
            {
              fe_id: Random.id(),
              type: "questionParagraph",
              title: "段落",
              isHidden: false,
              isLocked: false,
              props: {
                text: "这是一大段段落",
                isCenter: false,
              },
            },
            {
              fe_id: Random.id(),
              type: "questionInfo",
              title: "问卷信息",
              isHidden: false,
              isLocked: false,
              props: {
                title: "这是问卷标题",
                desc: "一大段描述",
              },
            },
            {
              fe_id: Random.id(),
              type: "questionRadio",
              title: "单选信息",
              isHidden: false,
              isLocked: false,
              props: {
                title: "这是单选",
                options: [
                  { value: "0", label: "1" },
                  { value: "1", label: "2" },
                ],
                isVertical: false,
                value: "0",
              },
            },
            {
              fe_id: Random.id(),
              type: "questionCheckbox",
              title: "多选信息",
              isHidden: false,
              isLocked: false,
              props: {
                title: "这是多选",
                list: [
                  { value: "0", label: "1", checked: false },
                  { value: "1", label: "2", checked: true },
                ],
                isVertical: false,
              },
            },
          ],
        },
      };
    },
  },
  // 创建试卷
  {
    url: `/api/question`,
    method: "post",
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
        },
      };
    },
  },
  // 获取(查询)问卷列表
  {
    url: `/api/question`,
    method: "get",
    response(ctx) {
      const { url = "", query = {} } = ctx;
      const isDeleted = url.indexOf("isDeleted=true") >= 0;
      const isStar = url.indexOf("isStar=true") >= 0;
      const pageSize = parseInt(query.pageSize || 10);
      const page = parseInt(query.page || 1);
      return {
        errno: 0,
        data: {
          list: getQuestionList({ isDeleted, isStar, page, pageSize }),
          total: 100,
        },
      };
    },
  },
  // 更新问卷
  {
    url: `/api/question/:id`,
    method: "patch",
    response(ctx) {
      return {
        errno: 0,
      };
    },
  },
  {
    url: `/api/question/duplicate/:id`,
    method: "post",
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
        },
      };
    },
  },
  {
    url: `/api/question`,
    method: "delete",
    response() {
      return {
        errno: 0,
      };
    },
  },
];
